package com.jerry.chinesechess.view;

import com.jerry.chinesechess.model.Board;
import com.jerry.chinesechess.model.Position;
import com.jerry.chinesechess.util.Constants;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;

public class ChessBoardView extends Pane {
    private final Board board;

    public ChessBoardView(Board board) {
        this.board = board;
        initializeBoard();
    }
    
    private void initializeBoard() {
        setPrefSize(Constants.BOARD_WIDTH * Constants.SQUARE_SIZE,
                   Constants.BOARD_HEIGHT * Constants.SQUARE_SIZE);
        
        // 绘制棋盘背景
        Rectangle background = new Rectangle(
            0, 0, 
            Constants.BOARD_WIDTH * Constants.SQUARE_SIZE, 
            Constants.BOARD_HEIGHT * Constants.SQUARE_SIZE
        );
        background.setFill(Constants.BOARD_COLOR);
        getChildren().add(background);
        
        // 绘制横线
        for (int row = 0; row <= Constants.BOARD_HEIGHT; row++) {
            Line line = new Line(
                0, row * Constants.SQUARE_SIZE,
                Constants.BOARD_WIDTH * Constants.SQUARE_SIZE, row * Constants.SQUARE_SIZE
            );
            line.setStroke(Color.BLACK);
            line.setStrokeWidth(2);
            getChildren().add(line);
        }
        
        // 绘制竖线和九宫格等...
        
        // 绘制棋子
        drawPieces();
    }
    
    private void drawPieces() {
        // 遍历board中的棋子并创建PieceView
    }
    
    public void updateView() {
        getChildren().removeIf(node -> false);
        drawPieces();
    }
}